<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *供货商对账
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
);
$install = check_account_permission('jy_merch');
if(!$install){
	exi('请联系管理员开启<多商户>！','error');
}
//供货商对账
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['ispay']=1;
	$params['merchid >']=0;
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	if(!empty($_RQ['ordersn'])){
		$params['ordersn']=trim($_RQ['ordersn']);
		$return['params']['ordersn']=$_RQ['ordersn'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','mid','ordersn','status','createtime','ispay','price','merchid');
	$list=pdo_getslice('jy_weishop_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']));
			$item['nickname']=$member['nickname'];
			$item['avatar']=$member['avatar'];
			$merch=pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['merchid']));
			$item['merchtitle']=$merch['merchname']?:'无';
			$item['merchimg']=$merch['logo'];
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'ordersn','title'=>'单号','type'=>'string'),
			array('name'=>'avatar','title'=>'用户头像','type'=>'image'),
			array('name'=>'nickname','title'=>'用户昵称','type'=>'string'),
			array('type'=>'img_string','title'=>'商户信息','img'=>'merchimg',
			'data'=>array(
				array('title'=>'ID：','name'=>'merchid'),
				array('title'=>'名称：','name'=>'merchtitle')
				)
			),
			array('name'=>'price','title'=>'金额','type'=>'string'),
			array('name'=>'createtime','title'=>'下单时间','type'=>'time'),
			array('name'=>'status','title'=>'订单状态','type'=>'radio','options'=>'order_status'),
		)),
		'search'=>array(
			array('name'=>'ordersn','width'=>15,'title'=>'单号','type'=>'string'),
		)
	);
	$return['order_status']=$this->order_status;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_weishop_order',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}